package cn.stylefeng.guns.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.system.entity.CheckAfterIndent;
import cn.stylefeng.guns.modular.system.mapper.CheckAfterIndentMapper;
import cn.stylefeng.guns.modular.system.model.params.CheckAfterIndentParam;
import cn.stylefeng.guns.modular.system.model.result.CheckAfterIndentResult;
import  cn.stylefeng.guns.modular.system.service.CheckAfterIndentService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 审核记录 服务实现类
 * </p>
 *
 * @author 小飞
 * @since 2019-07-10
 */
@Service
public class CheckAfterIndentServiceImpl extends ServiceImpl<CheckAfterIndentMapper, CheckAfterIndent> implements CheckAfterIndentService {

    @Override
    public void add(CheckAfterIndentParam param){
        CheckAfterIndent entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(CheckAfterIndentParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(CheckAfterIndentParam param){
        CheckAfterIndent oldEntity = getOldEntity(param);
        CheckAfterIndent newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public CheckAfterIndentResult findBySpec(CheckAfterIndentParam param){
        return null;
    }

    @Override
    public List<CheckAfterIndentResult> findListBySpec(CheckAfterIndentParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(CheckAfterIndentParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(CheckAfterIndentParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private CheckAfterIndent getOldEntity(CheckAfterIndentParam param) {
        return this.getById(getKey(param));
    }

    private CheckAfterIndent getEntity(CheckAfterIndentParam param) {
        CheckAfterIndent entity = new CheckAfterIndent();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
